package weaver.interfaces.xfjt.action;

import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.common.DateUtil;
import weaver.conn.RecordSet;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-10-07
 * @Description: 周期任务反馈流程归档更新任务台账状态和信息
 * @ModifyLog:
 **/
public class WeaCyclebackTaskAction extends BaseBean implements Action {
    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String currentDate = DateUtil.getCurrentDate();
        writeLog( ">>>>WeaCyclebackTaskAction>>>requestid=" + requestid);
        RecordSet rs = new RecordSet();
        try {
            rs.executeQuery( "select * from " + tablename + " where requestid=?", requestid );
            rs.next();
            //建模数据ID
            String jmid = Util.null2String( rs.getString( "jmid" ) );
            String fkrq = Util.null2String( rs.getString( "fkrq" ) );
            String fknr = Util.null2String( rs.getString( "fknr" ) );
            String fkfj = Util.null2String( rs.getString( "fkfj" ) );
            String zqjsrq = Util.null2String( rs.getString( "zqjsrq" ) );

            rs.executeUpdate( "update uf_zqrwtz_dt1 set fkrq=?,fknr=?,fkfj=?,wcrq=?,sfwcfk=0 " +
                    "where mainid=? and fklc=?", fkrq, fknr, fkfj, currentDate, jmid, requestid );
            writeLog( ">>>>WeaCyclebackTaskAction>>>zqjsrq=" + zqjsrq+",currentDate="+currentDate );
            int datevalue = DateUtil.compDate(currentDate,zqjsrq);
            writeLog( ">>>>WeaCyclebackTaskAction>>>datevalue=" + datevalue);
            if(datevalue < 0){
                rs.executeQuery( "select sfwcfk from uf_zqrwtz_dt1 where mainid=?", jmid );
                int counts = rs.getCounts();
                int count=0;
                while (rs.next()) {
                    String sfwcfk = Util.null2String( rs.getString("sfwcfk") );
                    if("1".equals( sfwcfk )){
                        count++;
                    }
                }
                writeLog( ">>>>WeaCyclebackTaskAction>>>count=" + count );
                if (count == 0 && counts > 0) {
                    rs.executeUpdate( "update uf_zqrwtz set rwzt=1,sjwcrq=? where id=?", currentDate, jmid );
                }
            }

            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }
    }

}
